package com.hzdesk.media.matvector.koreabatch.client.my_paperless.logic.view;

import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hzdesk.media.matvector.koreabatch.client.my_paperless.R;
import com.hzdesk.media.matvector.koreabatch.client.my_paperless.base.BaseActivity;
import com.hzdesk.media.matvector.koreabatch.client.my_paperless.bean.SetCurrentMeetingBean;
import com.hzdesk.media.matvector.koreabatch.client.my_paperless.logic.contract.ISetCurrentMeetingContract;
import com.hzdesk.media.matvector.koreabatch.client.my_paperless.logic.persenter.SetCurrentMeetingPersenter;
import com.hzdesk.media.matvector.koreabatch.client.my_paperless.utils.MyToastUtils;

/**
 * Created by Administrator on 2018/8/13.
 * 杭州席媒科技有限公司  Developers  刘传华  10
 * 佛祖镇楼 bug辟易
 */

public class SetCurrentMeetingActivity extends BaseActivity implements View.OnClickListener,ISetCurrentMeetingContract.ISetCurrentMeetingView {

    private String TAG = SetCurrentMeetingActivity.class.getSimpleName();
    private ImageView iv_is_selector;
    private RelativeLayout rl_change_metting_name_right_return;
    private RelativeLayout rl_add_personnel_right_return;
    private SetCurrentMeetingBean tbean;

    private SetCurrentMeetingPersenter mSetCurrentMeetingPersenter = new SetCurrentMeetingPersenter(this);
    private TextView tv_metting_neme;
    private TextView tv_metting_person_number;
    private Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if(msg.what == 1){
                if(return_change_name != null && !TextUtils.isEmpty(return_change_name)){
                    tv_metting_neme.setText(return_change_name);
                    if(tbean != null){
                        tbean.setName(return_change_name);
                        mSetCurrentMeetingPersenter.changeName(SetCurrentMeetingActivity.this,tbean);
                    }
                }
            }
        }
    };
    private String return_change_name;

    @Override
    protected void userAgreedPermissions() {

    }

    @Override
    protected View AddLayoutView() {
        View view = View.inflate(this, R.layout.activity_set_current_meeting,null);
        iv_is_selector = view.findViewById(R.id.activity_set_current_meeting_iv_is_selector);
        rl_change_metting_name_right_return = view.findViewById(R.id.activity_set_current_meeting_rl_change_metting_name_right_return);
        rl_add_personnel_right_return = view.findViewById(R.id.activity_set_current_meeting_rl_add_personnel_right_return);
        tv_metting_neme = view.findViewById(R.id.activity_set_current_meeting_tv_metting_neme);
        tv_metting_person_number = view.findViewById(R.id.activity_set_current_meeting_tv_metting_person_number);

        return view;
    }

    @Override
    protected void initChildViewDate() {
        mSetCurrentMeetingPersenter.initTitle();
       String metting_info_id =  getIntent().getStringExtra("metting_info_id");
        iv_is_selector.setOnClickListener(this);
        rl_change_metting_name_right_return.setOnClickListener(this);
        rl_add_personnel_right_return.setOnClickListener(this);
        mSetCurrentMeetingPersenter.LoadDate(this,metting_info_id);
    }

    @Override
    protected void onClickedTvRight() {

    }

    @Override
    protected void onClickedIvRight() {

    }

    @Override
    protected void onClickedIvLeft() {
        finish();
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.activity_set_current_meeting_iv_is_selector:
                if(tbean != null){
                    mSetCurrentMeetingPersenter.selectorWhetherPublic(tbean,this);
                }
                break;
            case R.id.activity_set_current_meeting_rl_change_metting_name_right_return:
                Intent intent = new Intent(this,ChangeMettingNameActivity.class);
                intent.putExtra("change_name_pager",2);
                startActivityForResult(intent, 2);
                break;
            case R.id.activity_set_current_meeting_rl_add_personnel_right_return:
                toPageJump(MyOrganizationActivity.class);
                break;
        }
    }

    @Override
    public void showPublic() {
        iv_is_selector.setImageResource(R.mipmap.right_is_selected);
    }

    @Override
    public void showWhether() {
        iv_is_selector.setImageResource(R.mipmap.left_no_selected);
    }

    @Override
    public void showTitle() {
        showTilteBg();
        showTitleContent();
        showTileIvLeft();
        //设备管理(6)
        setTitleContent("设置当前会议", 0xffffffff);
        setIvLeftIcon(R.mipmap.left_white_return);

    }

    @Override
    public void setMettingInfo(SetCurrentMeetingBean bean) {
        tbean = bean;
      int mettingshare =   bean.getMeetShare();
        if(mettingshare == 20){
            iv_is_selector.setImageResource(R.mipmap.left_no_selected);
        }else{
            iv_is_selector.setImageResource(R.mipmap.right_is_selected);
        }
      String name =   bean.getName();
        tv_metting_neme.setText(name);
       int smonth =  bean.getSmonth();
        tv_metting_person_number.setText("目前共"+smonth+"人");
    }

    @Override
    public void showToastMessage(String message) {
        MyToastUtils.ShortToaseShow(this,message);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if(resultCode == 2){
            return_change_name = data.getStringExtra("return_change_name");
            Log.e(TAG, "onActivityResult: return_change_name  _______________>  "+ return_change_name);
            if(return_change_name != null && !TextUtils.isEmpty(return_change_name)){
                Message msg =  Message.obtain();
                msg.what =1;
                handler.sendMessage(msg);
            }
        }
    }
}
